<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>padnavigator.cpp 示例文件 | Qt Widgets 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-graphicsview-padnavigator-example.html">Pad Navigator Example</a></td><td >padnavigator.cpp 示例文件</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtwidgets-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">padnavigator.cpp 示例文件</h1>
<span class="subtitle">graphicsview/padnavigator/padnavigator.cpp</span>
<!-- $$$graphicsview/padnavigator/padnavigator.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the examples of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#include &quot;flippablepad.h&quot;</span>
  <span class="preprocessor">#include &quot;padnavigator.h&quot;</span>
  <span class="preprocessor">#include &quot;splashitem.h&quot;</span>

  <span class="preprocessor">#ifndef QT_NO_OPENGL</span>
  <span class="preprocessor">#include &lt;QtOpenGL&gt;</span>
  <span class="preprocessor">#else</span>
  <span class="preprocessor">#include &lt;QtWidgets&gt;</span>
  <span class="preprocessor">#endif</span>

  PadNavigator<span class="operator">::</span>PadNavigator(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qsize.html">QSize</a></span> <span class="operator">&amp;</span>size<span class="operator">,</span> <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent)
      : <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span>(parent)
  {
      <span class="comment">// Splash item</span>
      SplashItem <span class="operator">*</span>splash <span class="operator">=</span> <span class="keyword">new</span> SplashItem;
      splash<span class="operator">-</span><span class="operator">&gt;</span>setZValue(<span class="number">1</span>);

      <span class="comment">// Pad item</span>
      FlippablePad <span class="operator">*</span>pad <span class="operator">=</span> <span class="keyword">new</span> FlippablePad(size);
      <span class="type"><a href="qgraphicsrotation.html">QGraphicsRotation</a></span> <span class="operator">*</span>flipRotation <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgraphicsrotation.html">QGraphicsRotation</a></span>(pad);
      <span class="type"><a href="qgraphicsrotation.html">QGraphicsRotation</a></span> <span class="operator">*</span>xRotation <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgraphicsrotation.html">QGraphicsRotation</a></span>(pad);
      <span class="type"><a href="qgraphicsrotation.html">QGraphicsRotation</a></span> <span class="operator">*</span>yRotation <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgraphicsrotation.html">QGraphicsRotation</a></span>(pad);
      flipRotation<span class="operator">-</span><span class="operator">&gt;</span>setAxis(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>YAxis);
      xRotation<span class="operator">-</span><span class="operator">&gt;</span>setAxis(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>YAxis);
      yRotation<span class="operator">-</span><span class="operator">&gt;</span>setAxis(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>XAxis);
      pad<span class="operator">-</span><span class="operator">&gt;</span>setTransformations(<span class="type"><a href="../qtcore/qlist.html">QList</a></span><span class="operator">&lt;</span><span class="type"><a href="qgraphicstransform.html">QGraphicsTransform</a></span> <span class="operator">*</span><span class="operator">&gt;</span>()
                              <span class="operator">&lt;</span><span class="operator">&lt;</span> flipRotation
                              <span class="operator">&lt;</span><span class="operator">&lt;</span> xRotation <span class="operator">&lt;</span><span class="operator">&lt;</span> yRotation);

      <span class="comment">// Back (proxy widget) item</span>
      <span class="type"><a href="qgraphicsproxywidget.html">QGraphicsProxyWidget</a></span> <span class="operator">*</span>backItem <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgraphicsproxywidget.html">QGraphicsProxyWidget</a></span>(pad);
      <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>widget <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qwidget.html">QWidget</a></span>;
      form<span class="operator">.</span>setupUi(widget);
      form<span class="operator">.</span>hostName<span class="operator">-</span><span class="operator">&gt;</span>setFocus();
      backItem<span class="operator">-</span><span class="operator">&gt;</span>setWidget(widget);
      backItem<span class="operator">-</span><span class="operator">&gt;</span>setVisible(<span class="keyword">false</span>);
      backItem<span class="operator">-</span><span class="operator">&gt;</span>setFocus();
      backItem<span class="operator">-</span><span class="operator">&gt;</span>setCacheMode(<span class="type"><a href="qgraphicsitem.html">QGraphicsItem</a></span><span class="operator">::</span>ItemCoordinateCache);
      <span class="keyword">const</span> <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> r <span class="operator">=</span> backItem<span class="operator">-</span><span class="operator">&gt;</span>rect();
      backItem<span class="operator">-</span><span class="operator">&gt;</span>setTransform(<span class="type"><a href="../qtgui/qtransform.html">QTransform</a></span>()
                             <span class="operator">.</span>rotate(<span class="number">180</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>YAxis)
                             <span class="operator">.</span>translate(<span class="operator">-</span>r<span class="operator">.</span>width()<span class="operator">/</span><span class="number">2</span><span class="operator">,</span> <span class="operator">-</span>r<span class="operator">.</span>height()<span class="operator">/</span><span class="number">2</span>));

      <span class="comment">// Selection item</span>
      RoundRectItem <span class="operator">*</span>selectionItem <span class="operator">=</span> <span class="keyword">new</span> RoundRectItem(<span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span>(<span class="operator">-</span><span class="number">60</span><span class="operator">,</span> <span class="operator">-</span><span class="number">60</span><span class="operator">,</span> <span class="number">120</span><span class="operator">,</span> <span class="number">120</span>)<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>gray<span class="operator">,</span> pad);
      selectionItem<span class="operator">-</span><span class="operator">&gt;</span>setZValue(<span class="number">0.5</span>);

      <span class="comment">// Splash animations</span>
      <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span> <span class="operator">*</span>smoothSplashMove <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span>(splash<span class="operator">,</span> <span class="string">&quot;y&quot;</span>);
      <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span> <span class="operator">*</span>smoothSplashOpacity <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span>(splash<span class="operator">,</span> <span class="string">&quot;opacity&quot;</span>);
      smoothSplashMove<span class="operator">-</span><span class="operator">&gt;</span>setEasingCurve(<span class="type"><a href="../qtcore/qeasingcurve.html">QEasingCurve</a></span><span class="operator">::</span>InQuad);
      smoothSplashMove<span class="operator">-</span><span class="operator">&gt;</span>setDuration(<span class="number">250</span>);
      smoothSplashOpacity<span class="operator">-</span><span class="operator">&gt;</span>setDuration(<span class="number">250</span>);

      <span class="comment">// Selection animation</span>
      <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span> <span class="operator">*</span>smoothXSelection <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span>(selectionItem<span class="operator">,</span> <span class="string">&quot;x&quot;</span>);
      <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span> <span class="operator">*</span>smoothYSelection <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span>(selectionItem<span class="operator">,</span> <span class="string">&quot;y&quot;</span>);
      <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span> <span class="operator">*</span>smoothXRotation <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span>(xRotation<span class="operator">,</span> <span class="string">&quot;angle&quot;</span>);
      <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span> <span class="operator">*</span>smoothYRotation <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span>(yRotation<span class="operator">,</span> <span class="string">&quot;angle&quot;</span>);
      smoothXSelection<span class="operator">-</span><span class="operator">&gt;</span>setDuration(<span class="number">125</span>);
      smoothYSelection<span class="operator">-</span><span class="operator">&gt;</span>setDuration(<span class="number">125</span>);
      smoothXRotation<span class="operator">-</span><span class="operator">&gt;</span>setDuration(<span class="number">125</span>);
      smoothYRotation<span class="operator">-</span><span class="operator">&gt;</span>setDuration(<span class="number">125</span>);
      smoothXSelection<span class="operator">-</span><span class="operator">&gt;</span>setEasingCurve(<span class="type"><a href="../qtcore/qeasingcurve.html">QEasingCurve</a></span><span class="operator">::</span>InOutQuad);
      smoothYSelection<span class="operator">-</span><span class="operator">&gt;</span>setEasingCurve(<span class="type"><a href="../qtcore/qeasingcurve.html">QEasingCurve</a></span><span class="operator">::</span>InOutQuad);
      smoothXRotation<span class="operator">-</span><span class="operator">&gt;</span>setEasingCurve(<span class="type"><a href="../qtcore/qeasingcurve.html">QEasingCurve</a></span><span class="operator">::</span>InOutQuad);
      smoothYRotation<span class="operator">-</span><span class="operator">&gt;</span>setEasingCurve(<span class="type"><a href="../qtcore/qeasingcurve.html">QEasingCurve</a></span><span class="operator">::</span>InOutQuad);

      <span class="comment">// Flip animation setup</span>
      <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span> <span class="operator">*</span>smoothFlipRotation <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span>(flipRotation<span class="operator">,</span> <span class="string">&quot;angle&quot;</span>);
      <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span> <span class="operator">*</span>smoothFlipScale <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span>(pad<span class="operator">,</span> <span class="string">&quot;scale&quot;</span>);
      <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span> <span class="operator">*</span>smoothFlipXRotation <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span>(xRotation<span class="operator">,</span> <span class="string">&quot;angle&quot;</span>);
      <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span> <span class="operator">*</span>smoothFlipYRotation <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span>(yRotation<span class="operator">,</span> <span class="string">&quot;angle&quot;</span>);
      <span class="type"><a href="../qtcore/qparallelanimationgroup.html">QParallelAnimationGroup</a></span> <span class="operator">*</span>flipAnimation <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qparallelanimationgroup.html">QParallelAnimationGroup</a></span>(<span class="keyword">this</span>);
      smoothFlipScale<span class="operator">-</span><span class="operator">&gt;</span>setDuration(<span class="number">500</span>);
      smoothFlipRotation<span class="operator">-</span><span class="operator">&gt;</span>setDuration(<span class="number">500</span>);
      smoothFlipXRotation<span class="operator">-</span><span class="operator">&gt;</span>setDuration(<span class="number">500</span>);
      smoothFlipYRotation<span class="operator">-</span><span class="operator">&gt;</span>setDuration(<span class="number">500</span>);
      smoothFlipScale<span class="operator">-</span><span class="operator">&gt;</span>setEasingCurve(<span class="type"><a href="../qtcore/qeasingcurve.html">QEasingCurve</a></span><span class="operator">::</span>InOutQuad);
      smoothFlipRotation<span class="operator">-</span><span class="operator">&gt;</span>setEasingCurve(<span class="type"><a href="../qtcore/qeasingcurve.html">QEasingCurve</a></span><span class="operator">::</span>InOutQuad);
      smoothFlipXRotation<span class="operator">-</span><span class="operator">&gt;</span>setEasingCurve(<span class="type"><a href="../qtcore/qeasingcurve.html">QEasingCurve</a></span><span class="operator">::</span>InOutQuad);
      smoothFlipYRotation<span class="operator">-</span><span class="operator">&gt;</span>setEasingCurve(<span class="type"><a href="../qtcore/qeasingcurve.html">QEasingCurve</a></span><span class="operator">::</span>InOutQuad);
      smoothFlipScale<span class="operator">-</span><span class="operator">&gt;</span>setKeyValueAt(<span class="number">0</span><span class="operator">,</span> qvariant_cast<span class="operator">&lt;</span><span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span><span class="operator">&gt;</span>(<span class="number">1.0</span>));
      smoothFlipScale<span class="operator">-</span><span class="operator">&gt;</span>setKeyValueAt(<span class="number">0.5</span><span class="operator">,</span> qvariant_cast<span class="operator">&lt;</span><span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span><span class="operator">&gt;</span>(<span class="number">0.7</span>));
      smoothFlipScale<span class="operator">-</span><span class="operator">&gt;</span>setKeyValueAt(<span class="number">1</span><span class="operator">,</span> qvariant_cast<span class="operator">&lt;</span><span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span><span class="operator">&gt;</span>(<span class="number">1.0</span>));
      flipAnimation<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(smoothFlipRotation);
      flipAnimation<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(smoothFlipScale);
      flipAnimation<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(smoothFlipXRotation);
      flipAnimation<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(smoothFlipYRotation);

      <span class="comment">// Flip animation delayed property assignment</span>
      <span class="type"><a href="../qtcore/qsequentialanimationgroup.html">QSequentialAnimationGroup</a></span> <span class="operator">*</span>setVariablesSequence <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qsequentialanimationgroup.html">QSequentialAnimationGroup</a></span>;
      <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span> <span class="operator">*</span>setFillAnimation <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span>(pad<span class="operator">,</span> <span class="string">&quot;fill&quot;</span>);
      <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span> <span class="operator">*</span>setBackItemVisibleAnimation <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span>(backItem<span class="operator">,</span> <span class="string">&quot;visible&quot;</span>);
      <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span> <span class="operator">*</span>setSelectionItemVisibleAnimation <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span>(selectionItem<span class="operator">,</span> <span class="string">&quot;visible&quot;</span>);
      setFillAnimation<span class="operator">-</span><span class="operator">&gt;</span>setDuration(<span class="number">0</span>);
      setBackItemVisibleAnimation<span class="operator">-</span><span class="operator">&gt;</span>setDuration(<span class="number">0</span>);
      setSelectionItemVisibleAnimation<span class="operator">-</span><span class="operator">&gt;</span>setDuration(<span class="number">0</span>);
      setVariablesSequence<span class="operator">-</span><span class="operator">&gt;</span>addPause(<span class="number">250</span>);
      setVariablesSequence<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(setBackItemVisibleAnimation);
      setVariablesSequence<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(setSelectionItemVisibleAnimation);
      setVariablesSequence<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(setFillAnimation);
      flipAnimation<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(setVariablesSequence);

      <span class="comment">// Build the state machine</span>
      <span class="type"><a href="../qtcore/qstatemachine.html">QStateMachine</a></span> <span class="operator">*</span>stateMachine <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qstatemachine.html">QStateMachine</a></span>(<span class="keyword">this</span>);
      <span class="type"><a href="../qtcore/qstate.html">QState</a></span> <span class="operator">*</span>splashState <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qstate.html">QState</a></span>(stateMachine);
      <span class="type"><a href="../qtcore/qstate.html">QState</a></span> <span class="operator">*</span>frontState <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qstate.html">QState</a></span>(stateMachine);
      <span class="type"><a href="../qtcore/qhistorystate.html">QHistoryState</a></span> <span class="operator">*</span>historyState <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qhistorystate.html">QHistoryState</a></span>(frontState);
      <span class="type"><a href="../qtcore/qstate.html">QState</a></span> <span class="operator">*</span>backState <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qstate.html">QState</a></span>(stateMachine);
      frontState<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(pad<span class="operator">,</span> <span class="string">&quot;fill&quot;</span><span class="operator">,</span> <span class="keyword">false</span>);
      frontState<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(splash<span class="operator">,</span> <span class="string">&quot;opacity&quot;</span><span class="operator">,</span> <span class="number">0.0</span>);
      frontState<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(backItem<span class="operator">,</span> <span class="string">&quot;visible&quot;</span><span class="operator">,</span> <span class="keyword">false</span>);
      frontState<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(flipRotation<span class="operator">,</span> <span class="string">&quot;angle&quot;</span><span class="operator">,</span> qvariant_cast<span class="operator">&lt;</span><span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span><span class="operator">&gt;</span>(<span class="number">0.0</span>));
      frontState<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(selectionItem<span class="operator">,</span> <span class="string">&quot;visible&quot;</span><span class="operator">,</span> <span class="keyword">true</span>);
      backState<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(pad<span class="operator">,</span> <span class="string">&quot;fill&quot;</span><span class="operator">,</span> <span class="keyword">true</span>);
      backState<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(backItem<span class="operator">,</span> <span class="string">&quot;visible&quot;</span><span class="operator">,</span> <span class="keyword">true</span>);
      backState<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(xRotation<span class="operator">,</span> <span class="string">&quot;angle&quot;</span><span class="operator">,</span> qvariant_cast<span class="operator">&lt;</span><span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span><span class="operator">&gt;</span>(<span class="number">0.0</span>));
      backState<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(yRotation<span class="operator">,</span> <span class="string">&quot;angle&quot;</span><span class="operator">,</span> qvariant_cast<span class="operator">&lt;</span><span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span><span class="operator">&gt;</span>(<span class="number">0.0</span>));
      backState<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(flipRotation<span class="operator">,</span> <span class="string">&quot;angle&quot;</span><span class="operator">,</span> qvariant_cast<span class="operator">&lt;</span><span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span><span class="operator">&gt;</span>(<span class="number">180.0</span>));
      backState<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(selectionItem<span class="operator">,</span> <span class="string">&quot;visible&quot;</span><span class="operator">,</span> <span class="keyword">false</span>);
      stateMachine<span class="operator">-</span><span class="operator">&gt;</span>addDefaultAnimation(smoothXRotation);
      stateMachine<span class="operator">-</span><span class="operator">&gt;</span>addDefaultAnimation(smoothYRotation);
      stateMachine<span class="operator">-</span><span class="operator">&gt;</span>addDefaultAnimation(smoothXSelection);
      stateMachine<span class="operator">-</span><span class="operator">&gt;</span>addDefaultAnimation(smoothYSelection);
      stateMachine<span class="operator">-</span><span class="operator">&gt;</span>setInitialState(splashState);

      <span class="comment">// Transitions</span>
      <span class="type"><a href="../qtcore/qeventtransition.html">QEventTransition</a></span> <span class="operator">*</span>anyKeyTransition <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qeventtransition.html">QEventTransition</a></span>(<span class="keyword">this</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qevent.html">QEvent</a></span><span class="operator">::</span>KeyPress<span class="operator">,</span> splashState);
      anyKeyTransition<span class="operator">-</span><span class="operator">&gt;</span>setTargetState(frontState);
      anyKeyTransition<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(smoothSplashMove);
      anyKeyTransition<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(smoothSplashOpacity);

      <span class="type"><a href="qkeyeventtransition.html">QKeyEventTransition</a></span> <span class="operator">*</span>enterTransition <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qkeyeventtransition.html">QKeyEventTransition</a></span>(<span class="keyword">this</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qevent.html">QEvent</a></span><span class="operator">::</span>KeyPress<span class="operator">,</span>
                                                                     <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Key_Enter<span class="operator">,</span> backState);
      <span class="type"><a href="qkeyeventtransition.html">QKeyEventTransition</a></span> <span class="operator">*</span>returnTransition <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qkeyeventtransition.html">QKeyEventTransition</a></span>(<span class="keyword">this</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qevent.html">QEvent</a></span><span class="operator">::</span>KeyPress<span class="operator">,</span>
                                                                      <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Key_Return<span class="operator">,</span> backState);
      <span class="type"><a href="qkeyeventtransition.html">QKeyEventTransition</a></span> <span class="operator">*</span>backEnterTransition <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qkeyeventtransition.html">QKeyEventTransition</a></span>(<span class="keyword">this</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qevent.html">QEvent</a></span><span class="operator">::</span>KeyPress<span class="operator">,</span>
                                                                         <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Key_Enter<span class="operator">,</span> frontState);
      <span class="type"><a href="qkeyeventtransition.html">QKeyEventTransition</a></span> <span class="operator">*</span>backReturnTransition <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qkeyeventtransition.html">QKeyEventTransition</a></span>(<span class="keyword">this</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qevent.html">QEvent</a></span><span class="operator">::</span>KeyPress<span class="operator">,</span>
                                                                          <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Key_Return<span class="operator">,</span> frontState);
      enterTransition<span class="operator">-</span><span class="operator">&gt;</span>setTargetState(historyState);
      returnTransition<span class="operator">-</span><span class="operator">&gt;</span>setTargetState(historyState);
      backEnterTransition<span class="operator">-</span><span class="operator">&gt;</span>setTargetState(backState);
      backReturnTransition<span class="operator">-</span><span class="operator">&gt;</span>setTargetState(backState);
      enterTransition<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(flipAnimation);
      returnTransition<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(flipAnimation);
      backEnterTransition<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(flipAnimation);
      backReturnTransition<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(flipAnimation);

      <span class="comment">// Create substates for each icon; store in temporary grid.</span>
      <span class="type">int</span> columns <span class="operator">=</span> size<span class="operator">.</span>width();
      <span class="type">int</span> rows <span class="operator">=</span> size<span class="operator">.</span>height();
      <span class="type"><a href="../qtcore/qvector.html">QVector</a></span><span class="operator">&lt;</span> <span class="type"><a href="../qtcore/qvector.html">QVector</a></span><span class="operator">&lt;</span> <span class="type"><a href="../qtcore/qstate.html">QState</a></span> <span class="operator">*</span> <span class="operator">&gt;</span> <span class="operator">&gt;</span> stateGrid;
      stateGrid<span class="operator">.</span>resize(rows);
      <span class="keyword">for</span> (<span class="type">int</span> y <span class="operator">=</span> <span class="number">0</span>; y <span class="operator">&lt;</span> rows; <span class="operator">+</span><span class="operator">+</span>y) {
          stateGrid<span class="operator">[</span>y<span class="operator">]</span><span class="operator">.</span>resize(columns);
          <span class="keyword">for</span> (<span class="type">int</span> x <span class="operator">=</span> <span class="number">0</span>; x <span class="operator">&lt;</span> columns; <span class="operator">+</span><span class="operator">+</span>x)
              stateGrid<span class="operator">[</span>y<span class="operator">]</span><span class="operator">[</span>x<span class="operator">]</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qstate.html">QState</a></span>(frontState);
      }
      frontState<span class="operator">-</span><span class="operator">&gt;</span>setInitialState(stateGrid<span class="operator">[</span><span class="number">0</span><span class="operator">]</span><span class="operator">[</span><span class="number">0</span><span class="operator">]</span>);
      selectionItem<span class="operator">-</span><span class="operator">&gt;</span>setPos(pad<span class="operator">-</span><span class="operator">&gt;</span>iconAt(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span>)<span class="operator">-</span><span class="operator">&gt;</span>pos());

      <span class="comment">// Enable key navigation using state transitions</span>
      <span class="keyword">for</span> (<span class="type">int</span> y <span class="operator">=</span> <span class="number">0</span>; y <span class="operator">&lt;</span> rows; <span class="operator">+</span><span class="operator">+</span>y) {
          <span class="keyword">for</span> (<span class="type">int</span> x <span class="operator">=</span> <span class="number">0</span>; x <span class="operator">&lt;</span> columns; <span class="operator">+</span><span class="operator">+</span>x) {
              <span class="type"><a href="../qtcore/qstate.html">QState</a></span> <span class="operator">*</span>state <span class="operator">=</span> stateGrid<span class="operator">[</span>y<span class="operator">]</span><span class="operator">[</span>x<span class="operator">]</span>;
              <span class="type"><a href="qkeyeventtransition.html">QKeyEventTransition</a></span> <span class="operator">*</span>rightTransition <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qkeyeventtransition.html">QKeyEventTransition</a></span>(<span class="keyword">this</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qevent.html">QEvent</a></span><span class="operator">::</span>KeyPress<span class="operator">,</span>
                                                                             <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Key_Right<span class="operator">,</span> state);
              <span class="type"><a href="qkeyeventtransition.html">QKeyEventTransition</a></span> <span class="operator">*</span>leftTransition <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qkeyeventtransition.html">QKeyEventTransition</a></span>(<span class="keyword">this</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qevent.html">QEvent</a></span><span class="operator">::</span>KeyPress<span class="operator">,</span>
                                                                            <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Key_Left<span class="operator">,</span> state);
              <span class="type"><a href="qkeyeventtransition.html">QKeyEventTransition</a></span> <span class="operator">*</span>downTransition <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qkeyeventtransition.html">QKeyEventTransition</a></span>(<span class="keyword">this</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qevent.html">QEvent</a></span><span class="operator">::</span>KeyPress<span class="operator">,</span>
                                                                            <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Key_Down<span class="operator">,</span> state);
              <span class="type"><a href="qkeyeventtransition.html">QKeyEventTransition</a></span> <span class="operator">*</span>upTransition <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qkeyeventtransition.html">QKeyEventTransition</a></span>(<span class="keyword">this</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qevent.html">QEvent</a></span><span class="operator">::</span>KeyPress<span class="operator">,</span>
                                                                          <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Key_Up<span class="operator">,</span> state);
              rightTransition<span class="operator">-</span><span class="operator">&gt;</span>setTargetState(stateGrid<span class="operator">[</span>y<span class="operator">]</span><span class="operator">[</span>(x <span class="operator">+</span> <span class="number">1</span>) <span class="operator">%</span> columns<span class="operator">]</span>);
              leftTransition<span class="operator">-</span><span class="operator">&gt;</span>setTargetState(stateGrid<span class="operator">[</span>y<span class="operator">]</span><span class="operator">[</span>((x <span class="operator">-</span> <span class="number">1</span>) <span class="operator">+</span> columns) <span class="operator">%</span> columns<span class="operator">]</span>);
              downTransition<span class="operator">-</span><span class="operator">&gt;</span>setTargetState(stateGrid<span class="operator">[</span>(y <span class="operator">+</span> <span class="number">1</span>) <span class="operator">%</span> rows<span class="operator">]</span><span class="operator">[</span>x<span class="operator">]</span>);
              upTransition<span class="operator">-</span><span class="operator">&gt;</span>setTargetState(stateGrid<span class="operator">[</span>((y <span class="operator">-</span> <span class="number">1</span>) <span class="operator">+</span> rows) <span class="operator">%</span> rows<span class="operator">]</span><span class="operator">[</span>x<span class="operator">]</span>);
              RoundRectItem <span class="operator">*</span>icon <span class="operator">=</span> pad<span class="operator">-</span><span class="operator">&gt;</span>iconAt(x<span class="operator">,</span> y);
              state<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(xRotation<span class="operator">,</span> <span class="string">&quot;angle&quot;</span><span class="operator">,</span> <span class="operator">-</span>icon<span class="operator">-</span><span class="operator">&gt;</span>x() <span class="operator">/</span> <span class="number">6.0</span>);
              state<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(yRotation<span class="operator">,</span> <span class="string">&quot;angle&quot;</span><span class="operator">,</span> icon<span class="operator">-</span><span class="operator">&gt;</span>y() <span class="operator">/</span> <span class="number">6.0</span>);
              state<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(selectionItem<span class="operator">,</span> <span class="string">&quot;x&quot;</span><span class="operator">,</span> icon<span class="operator">-</span><span class="operator">&gt;</span>x());
              state<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(selectionItem<span class="operator">,</span> <span class="string">&quot;y&quot;</span><span class="operator">,</span> icon<span class="operator">-</span><span class="operator">&gt;</span>y());
              frontState<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(icon<span class="operator">,</span> <span class="string">&quot;visible&quot;</span><span class="operator">,</span> <span class="keyword">true</span>);
              backState<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(icon<span class="operator">,</span> <span class="string">&quot;visible&quot;</span><span class="operator">,</span> <span class="keyword">false</span>);

              <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span> <span class="operator">*</span>setIconVisibleAnimation <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qpropertyanimation.html">QPropertyAnimation</a></span>(icon<span class="operator">,</span> <span class="string">&quot;visible&quot;</span>);
              setIconVisibleAnimation<span class="operator">-</span><span class="operator">&gt;</span>setDuration(<span class="number">0</span>);
              setVariablesSequence<span class="operator">-</span><span class="operator">&gt;</span>addAnimation(setIconVisibleAnimation);
          }
      }

      <span class="comment">// Scene</span>
      <span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span> <span class="operator">*</span>scene <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span>(<span class="keyword">this</span>);
      scene<span class="operator">-</span><span class="operator">&gt;</span>setBackgroundBrush(<span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span>(<span class="string">&quot;:/images/blue_angle_swirl.jpg&quot;</span>));
      scene<span class="operator">-</span><span class="operator">&gt;</span>setItemIndexMethod(<span class="type"><a href="qgraphicsscene.html">QGraphicsScene</a></span><span class="operator">::</span>NoIndex);
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(pad);
      scene<span class="operator">-</span><span class="operator">&gt;</span>setSceneRect(scene<span class="operator">-</span><span class="operator">&gt;</span>itemsBoundingRect());
      setScene(scene);

      <span class="comment">// Adjust splash item to scene contents</span>
      <span class="keyword">const</span> <span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span> sbr <span class="operator">=</span> splash<span class="operator">-</span><span class="operator">&gt;</span>boundingRect();
      splash<span class="operator">-</span><span class="operator">&gt;</span>setPos(<span class="operator">-</span>sbr<span class="operator">.</span>width() <span class="operator">/</span> <span class="number">2</span><span class="operator">,</span> scene<span class="operator">-</span><span class="operator">&gt;</span>sceneRect()<span class="operator">.</span>top() <span class="operator">-</span> <span class="number">2</span>);
      frontState<span class="operator">-</span><span class="operator">&gt;</span>assignProperty(splash<span class="operator">,</span> <span class="string">&quot;y&quot;</span><span class="operator">,</span> splash<span class="operator">-</span><span class="operator">&gt;</span>y() <span class="operator">-</span> <span class="number">100.0</span>);
      scene<span class="operator">-</span><span class="operator">&gt;</span>addItem(splash);

      <span class="comment">// View</span>
      setVerticalScrollBarPolicy(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>ScrollBarAlwaysOff);
      setHorizontalScrollBarPolicy(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>ScrollBarAlwaysOff);
      setMinimumSize(<span class="number">50</span><span class="operator">,</span> <span class="number">50</span>);
      setViewportUpdateMode(FullViewportUpdate);
      setCacheMode(CacheBackground);
      setRenderHints(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>Antialiasing
                     <span class="operator">|</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>SmoothPixmapTransform
                     <span class="operator">|</span> <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>TextAntialiasing);
  <span class="preprocessor">#ifndef QT_NO_OPENGL</span>
      setViewport(<span class="keyword">new</span> <span class="type"><a href="qopenglwidget.html">QOpenGLWidget</a></span>);
  <span class="preprocessor">#endif</span>

      stateMachine<span class="operator">-</span><span class="operator">&gt;</span>start();
  }

  <span class="type">void</span> PadNavigator<span class="operator">::</span>resizeEvent(<span class="type"><a href="../qtgui/qresizeevent.html">QResizeEvent</a></span> <span class="operator">*</span>event)
  {
      <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span><span class="operator">::</span>resizeEvent(event);
      fitInView(scene()<span class="operator">-</span><span class="operator">&gt;</span>sceneRect()<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>KeepAspectRatio);
  }

</pre>
</div>
<!-- @@@graphicsview/padnavigator/padnavigator.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
